package TreeNodeSecond.SwordOffer;

import com.sun.deploy.util.StringUtils;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class ConvertBST {
    /**
     * 剑指 Offer II 054. 所有大于等于节点的值之和
     * 给定一个二叉搜索树，请将它的每个节点的值替换成树中大于或者等于该节点值的所有节点值之和。
     * 输入：root = [3,2,4,1]
     * 输出：[7,9,4,10]
     *
     * @param root
     * @return
     */
    int sum = 0;

    public TreeNode convertBST(TreeNode root) {
        if (root != null) {
            convertBST(root.right);
            sum += root.val;
            root.val = sum;
            convertBST(root.left);
        }
        return root;
    }

    public static void main(String[] args) {


//        String s = formatNumberWithUnit("1234");
//        System.out.println(s);
//        String s1 = formatNumberWithUnit("123456");
//        System.out.println(s1);
//        String s2 = formatNumberWithUnit("12345678");
//        System.out.println(s2);
//        String s3 = formatNumberWithUnit("123456789");
//        System.out.println(s3);
//        String s4 = formatNumberWithUnit("100000000");
//        System.out.println(s4);
//        String s5 = formatNumberWithUnit("34567");
//        System.out.println(s5);
//
//        String s6 = formatNumberWithUnit("2");
//        System.out.println(s6);
        Integer num = 1;
        if (num.equals(1)) {
            System.out.println(true);
        }  if (num == 1) {
            System.out.println(true);
        }
    }


    public static String formatNumberWithUnit(String needFormatNumber) {
        final String noNumDefaultValue = "0";

        String nuit = "", formatNumStr = "";
        StringBuffer sb = new StringBuffer();
        BigDecimal b1 = new BigDecimal("10000");
        BigDecimal b3 = new BigDecimal("10000000");
        BigDecimal b2 = new BigDecimal("100000000");
        BigDecimal needNum = new BigDecimal(needFormatNumber);

        if (needNum.compareTo(b1) == -1) {
            return needNum.toString();
        }
        // 以万为单位处理
        if ((needNum.compareTo(b1) == 0 || needNum.compareTo(b1) == 1) && needNum.compareTo(b3) == -1) {
            formatNumStr = needNum.divide(b1).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            nuit = "万";
        } else if (needNum.compareTo(b3) == 0 || needNum.compareTo(b3) == 1 && needNum.compareTo(b2) == -1) {
            formatNumStr = needNum.divide(b3).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            nuit = "千万";
        }
        // 以亿为单位处理
        else if (needNum.compareTo(b2) == 0 || needNum.compareTo(b2) == 1) {
            formatNumStr = needNum.divide(b2).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
            nuit = "亿";
        }

        if (!formatNumStr.isEmpty()) {
            sb.append(showAmountHandle(formatNumStr)).append(nuit);
        }

        if (sb.length() == 0) {
            return noNumDefaultValue;
        }

        return sb.toString();
    }

    public static String showAmountHandle(String finishedCount) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);
        return String.valueOf(nf.format(new BigDecimal(finishedCount).doubleValue()));
    }


}

class StoreDto {

    public StoreDto() {
    }

    private String storeCode;
    private String storeName;
    private Double brandTargetValue;

    @Override
    public String toString() {
        return "StoreDto{" +
                "storeCode='" + storeCode + '\'' +
                ", storeName='" + storeName + '\'' +
                '}';
    }

    public Double getBrandTargetValue() {
        return brandTargetValue;
    }

    public void setBrandTargetValue(Double brandTargetValue) {
        this.brandTargetValue = brandTargetValue;
    }

    public StoreDto(String storeCode, String storeName, Double brandTargetValue) {
        this.storeCode = storeCode;
        this.storeName = storeName;
        this.brandTargetValue = brandTargetValue;
    }

    public StoreDto(String storeCode, String storeName) {
        this.storeCode = storeCode;
        this.storeName = storeName;
    }

    public String getStoreCode() {
        return storeCode;
    }

    public void setStoreCode(String storeCode) {
        this.storeCode = storeCode;
    }

    public String getStoreName() {
        return storeName;
    }

    public void setStoreName(String storeName) {
        this.storeName = storeName;
    }
}
